{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from icepyx import icesat2data as ipd\n",
    "import os\n",
    "import shutil\n",
    "import geopandas as gpd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Download data for sea ice tutorial:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### set email and uid for earthdata:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "earthdata_email='your email here'\n",
    "earthdata_uid='your earthdata login'\n",
    "# earthdata_email='buckley@umd.edu'\n",
    "# earthdata_uid='emb4md'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### set folder path for downloaded data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_home='/home/jovyan/data'\n",
    "if not os.path.isdir(data_home):\n",
    "    os.mkdir(data_home)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### download granules required for tutorial:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set DOWNLOAD to true if you're ready to download the data:\n",
    "DOWNLOAD=False\n",
    "    \n",
    "requests=[\n",
    "    {   'short_name' : 'ATL03',\n",
    "        'spatial_extent' :[153.6, 79.98, 153.61, 79.99],\n",
    "        'date_range' : ['2019-02-06','2019-02-06']},\n",
    "    {   'short_name' : 'ATL03',\n",
    "        'spatial_extent' :[-38.8,64.63,-38.7,64.64],\n",
    "        'date_range' : ['2019-04-30','2019-04-30']},\n",
    "    {   'short_name' : 'ATL03',\n",
    "        'spatial_extent' :[99.5, 76.4, 99.6, 76.5],\n",
    "        'date_range' : ['2019-03-24','2019-03-24']},\n",
    "    {   'short_name' : 'ATL03',\n",
    "        'spatial_extent' :[-168.65,73.74,-168.64,73.75],\n",
    "        'date_range' : ['2018-11-15','2018-11-15']},\n",
    "    {   'short_name' : 'ATL07',\n",
    "        'spatial_extent' :[-38.8,64.63,-38.7,64.64],\n",
    "        'date_range' : ['2019-04-30','2019-04-30']},\n",
    "    {   'short_name' : 'ATL07',\n",
    "        'spatial_extent' :[99.5, 76.4, 99.6, 76.5],\n",
    "        'date_range' : ['2019-03-24','2019-03-24']},\n",
    "    {   'short_name' : 'ATL07',\n",
    "        'spatial_extent' :[-168.65,73.74,-168.64,73.75],\n",
    "        'date_range' : ['2018-11-15','2018-11-15']},\n",
    "    {   'short_name' : 'ATL10',\n",
    "        'spatial_extent' :[-168.65,73.74,-168.64,73.75],\n",
    "        'date_range' : ['2018-11-15','2018-11-15']}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ATL03\n",
      "['2019-02-06', '2019-02-06']\n",
      "00:00:00\n",
      "23:59:59\n",
      "003\n",
      "['bounding box', [153.6, 79.98, 153.61, 79.99]]\n",
      "ATL03\n",
      "['2019-04-30', '2019-04-30']\n",
      "00:00:00\n",
      "23:59:59\n",
      "003\n",
      "['bounding box', [-38.8, 64.63, -38.7, 64.64]]\n",
      "ATL03\n",
      "['2019-03-24', '2019-03-24']\n",
      "00:00:00\n",
      "23:59:59\n",
      "003\n",
      "['bounding box', [99.5, 76.4, 99.6, 76.5]]\n",
      "ATL03\n",
      "['2018-11-15', '2018-11-15']\n",
      "00:00:00\n",
      "23:59:59\n",
      "003\n",
      "['bounding box', [-168.65, 73.74, -168.64, 73.75]]\n",
      "ATL07\n",
      "['2019-04-30', '2019-04-30']\n",
      "00:00:00\n",
      "23:59:59\n",
      "002\n",
      "['bounding box', [-38.8, 64.63, -38.7, 64.64]]\n",
      "ATL07\n",
      "['2019-03-24', '2019-03-24']\n",
      "00:00:00\n",
      "23:59:59\n",
      "002\n",
      "['bounding box', [99.5, 76.4, 99.6, 76.5]]\n",
      "ATL07\n",
      "['2018-11-15', '2018-11-15']\n",
      "00:00:00\n",
      "23:59:59\n",
      "002\n",
      "['bounding box', [-168.65, 73.74, -168.64, 73.75]]\n",
      "ATL10\n",
      "['2018-11-15', '2018-11-15']\n",
      "00:00:00\n",
      "23:59:59\n",
      "002\n",
      "['bounding box', [-168.65, 73.74, -168.64, 73.75]]\n"
     ]
    }
   ],
   "source": [
    "for req in requests:\n",
    "    #### Download this data: (uncomment and run)\n",
    "    region_a = ipd.Icesat2Data(req['short_name'], req['spatial_extent'], req['date_range'])\n",
    "    if DOWNLOAD:\n",
    "        region_a.earthdata_login(earthdata_uid, earthdata_email)\n",
    "        region_a.download_granules(data_home,subset=False)\n",
    "#     print(region_a.dataset)\n",
    "#     print(region_a.dates)\n",
    "#     print(region_a.start_time)\n",
    "#     print(region_a.end_time)\n",
    "#     print(region_a.dataset_version)\n",
    "#     print(region_a.spatial_extent)\n",
    "#     region_a.visualize_spatial_extent()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:notebook] *",
   "language": "python",
   "name": "conda-env-notebook-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
